package com.hotel.config.rabbitmq.config;

import org.springframework.amqp.core.Binding;
import org.springframework.amqp.core.BindingBuilder;
import org.springframework.amqp.core.DirectExchange;
import org.springframework.amqp.core.Queue;
import org.springframework.context.annotation.Bean;
import org.springframework.context.annotation.Configuration;

import java.util.HashMap;
import java.util.Map;

@Configuration
public class CommentReplyConfig {
    
    public static final String COMMENT_REPLY_NORMAL = "comment_reply_normal";

    public static final String COMMENT_REPLY_QUEUE = "comment_reply_queue";

    public static final String COMMENT_REPLY_KEY = "comment_reply_key";

    public static final String COMMENT_REPLY_BEAN = "comment_reply_bean";

    public static final String DEAD_COMMENT_REPLY_NORMAL = "dead_comment_reply_normal";

    public static final String DEAD_COMMENT_REPLY_QUEUE = "dead_comment_reply_queue";

    public static final String DEAD_COMMENT_REPLY_KEY = "dead_comment_reply_key";

    public static final String DEAD_COMMENT_REPLY_BEAN = "dead_comment_reply_bean";
    
    @Bean(COMMENT_REPLY_NORMAL)
    public DirectExchange newCommentReplyNormal(){
        return new DirectExchange(COMMENT_REPLY_NORMAL,true,false);
    }
    
    @Bean(COMMENT_REPLY_QUEUE)
    public Queue newCommentReplyQueue(){
        Map<String, Object> map = new HashMap<>();
        map.put("x-dead-letter-exchange",DEAD_COMMENT_REPLY_NORMAL);
        map.put("x-dead-letter-routing-key",DEAD_COMMENT_REPLY_KEY);
        return new Queue(COMMENT_REPLY_QUEUE,true,false,false,map);
    }
    
    @Bean(COMMENT_REPLY_BEAN)
    public Binding Bind(){
        return BindingBuilder.bind(newCommentReplyQueue()).to(newCommentReplyNormal()).with(COMMENT_REPLY_KEY);
    }

    @Bean(DEAD_COMMENT_REPLY_BEAN)
    public DirectExchange newDeadCommentReplyNormal(){
        return new DirectExchange(DEAD_COMMENT_REPLY_BEAN,true,false);
    }

    @Bean(DEAD_COMMENT_REPLY_QUEUE)
    public Queue newDeadCommentReplyQueue(){
        return new Queue(DEAD_COMMENT_REPLY_QUEUE,true);
    }

    @Bean(DEAD_COMMENT_REPLY_BEAN)
    public Binding DeadBind(){
        return BindingBuilder.bind(newDeadCommentReplyQueue()).to(newDeadCommentReplyNormal()).with(DEAD_COMMENT_REPLY_KEY);
    }
    
}
